package com.jz.community.basecomm.base.baseSupport;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.jz.community.basecomm.mvp.BaseMvpPresenter;
import com.jz.community.basecomm.mvp.MVPContract;

/**
 * Created by Tony.Fan on 2018/3/15 13:48
 *
 */
public abstract class BaseMvpActivity<V extends MVPContract.View, P extends BaseMvpPresenter<V>> extends SupportActivity {

    protected P mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initPresenter();
    }

    private void initPresenter(){
        if (mPresenter == null) {
            mPresenter = createPresenter();
        }
        mPresenter.attachView((V) this);
    }

    protected abstract P createPresenter();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.detachView();
        }
    }
}
